package com.lixueju.security.box.web.config;

import com.lixueju.security.box.web.authentication.DefaultSecurityBoxLoginAfterImpl;
import com.lixueju.security.box.web.authentication.DefaultUserDetailsServiceImpl;
import com.lixueju.security.box.web.authentication.SecurityBoxLoginAfter;
import com.lixueju.security.box.web.support.SecurityBoxBindWeixinAfter;
import com.lixueju.security.box.web.support.SecurityBoxBindMobileAfter;
import com.lixueju.security.box.web.support.impl.DefaultSecurityBoxBindWeixinAfterImpl;
import com.lixueju.security.box.web.support.impl.DefaultSecurityBoxBindMobileAfterImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author lixueju
 * @since 2019/11/6 12:57
 **/
@Configuration
public class SecurityBoxBeanConfig {
    /**
     * 默认密码处理器
     *
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(PasswordEncoder.class)
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    /**
     * 默认认证器
     *
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(UserDetailsService.class)
    public UserDetailsService userDetailsService() {
        return new DefaultUserDetailsServiceImpl();
    }

    /**
     * 默认登录成功后处理实现
     *
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(SecurityBoxLoginAfter.class)
    public SecurityBoxLoginAfter securityBoxLoginAfter() {
        return new DefaultSecurityBoxLoginAfterImpl();
    }

    /**
     * 默认的绑定手机号后的实现
     */
    @Bean
    @ConditionalOnMissingBean(SecurityBoxBindMobileAfter.class)
    public SecurityBoxBindMobileAfter securityBoxBindWeixinMobileAfter() {
        return new DefaultSecurityBoxBindMobileAfterImpl();
    }

    /**
     * 默认的绑定微信后的实现
     */
    @Bean
    @ConditionalOnMissingBean(SecurityBoxBindWeixinAfter.class)
    public SecurityBoxBindWeixinAfter securityBoxBindWeixinAfter() {
        return new DefaultSecurityBoxBindWeixinAfterImpl();
    }
}
